home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / ln2chr.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  1KB  |  54 lines

  1. /*****************************************************************************
  2.  
  3.     Ln2Chr()
  4.  
  5.     This function converts an edit buffer offset represented by a line
  6. number into the corresponding character number.  It basically performs the
  7. function of the control-Q command.
  8.     The returned character offset is minimized with the edge of the
  9. buffer.  This means that if there are 10 lines in the edit buffer and this
  10. function is called to compute the character offset of the 100th line,  the
  11. character offset of the 10th line is returned.  Of course,  this happens
  12. whether the argument is positive or negative.
  13.  
  14. *****************************************************************************/
  15.  
  16. #include "zport.h"        /* define portability identifiers */
  17. #include "tecoc.h"        /* define general identifiers */
  18. #include "defext.h"        /* define external global variables */
  19. #include "dchars.h"        /* define identifiers for characters */
  20. #include "chmacs.h"        /* define character processing macros */
  21.  
  22. LONG Ln2Chr(Value)
  23. LONG Value;
  24. {
  25.     charptr    TmpPtr;
  26.  
  27.     if (Value > 0) {
  28.         TmpPtr = GapEnd;
  29.         while ((TmpPtr < EBfEnd) &&  (Value > 0)) {
  30.             ++TmpPtr;
  31.             if (IsEOL(*TmpPtr)) {
  32.                 --Value;
  33.             }
  34.         }
  35.         return TmpPtr-GapEnd;
  36.     }
  37.  
  38.     TmpPtr = GapBeg;
  39.     while ((TmpPtr > EBfBeg) && (Value <= 0)) {
  40.         --TmpPtr;
  41.         if (IsEOL(*TmpPtr)) {
  42.             ++Value;
  43.         }
  44.     }
  45.  
  46. /*
  47.  * at this point (Value > 0 OR TmpPtr == EBfBeg)
  48.  */
  49.     if ((TmpPtr != EBfBeg) || (IsEOL(*TmpPtr))) {
  50.         ++TmpPtr;
  51.     }
  52.     return TmpPtr-GapBeg;
  53. }
  54.